<meta content="text/html; charset=UTF-8; X-Content-Type-Options=nosniff" http-equiv="Content-Type" />
<style type="text/css">
    .redBorder{border: 1px solid red;}
	/*kendo MultiSelect CSS*/
    #ss_share_email_ms_div .k-input{border: 0px;text-indent: 0px; height: 16px!important; line-height: 16px!important;}
    #ss_share_email_ms_div .k-multiselect-wrap li{background-color: #C3C3C3!important; height: 22px; line-height: 22px; width: auto;}
    #ss_share_email_ms_div .focusBorder{border: 1px solid #d8d8d8;}
    #ss_share_email_ms_div .k-delete{margin-top: -6px; margin-right: 3px;}
    
    #ss_share_email_body a{text-decoration:none;}
    #ss_share_email_body .aEnable{cursor: pointer; color: #63B8FF!important;}
    #ss_share_email_body .divInline{display: inline;} 
	
    #ss_share_email_ms_div .k-button{
        cursor: default;
    }
    #ss_share_email_ms_div .k-delete{
        cursor: pointer;
    }
    /*#ss_share_email_body .aDisable{cursor: default; color: #000000!important;}*/
</style>
<div id="ss_share_email_win">
	<div id="ss_share_email_body" class="wp_ml_15 wp_mt_10 wp_mr_15 wp_fz_12">
		<div id="ss_share_email_ms_div" class="wp_mt_10">
			<input id="ss_share_email_ms_input" style="width: 482px;" class="wp_mt_5" />
		</div>
	    <div class="wp_fz_10">Enter User ID / Name</div>
    </div>
    <button id="ss_share_email_submit_btn" class="k-button wp_w_50 wp_h_20 right wp_fz_11 wp_mt_10 wp_mb_10 wp_mr_15">Submit</button>
</div>

<script type="text/javascript">
	var share_email_win = (function () {
		var winDiv = $('#ss_share_email_win'), expertsIdsStr, winTitle = 'Share via Email', scrollElem = $("#ss_share_email_body"), msDiv, viewMoreA, submitBtn, notificationTitle, notificationText, callbackFun, originalHtml = winDiv.html(), win, expertsIdsArray, loaderContent = {position:'center', imgColor:'black', textCSS:{'display': 'block', 'color':'black'}}, loader = new Workport.Loader(winDiv, loaderContent);

        winDiv.kendoWindow({width: '512px', title: winTitle, minHeight: 100, maxHeight: 530, modal: true, visible: false, resizable: false, draggable: false, actions:["Close"], 
            close: function () {
                winDiv.empty();
                winDiv.html(originalHtml);
            }
        });

        function init () {
            var msInput = $("#ss_share_email_ms_input"), expertsEEObj = {ids: [], names: [], idsStr: ""}, expertsMSObj;

            msDiv = $("#ss_share_email_ms_div");
            expertsMSObj = {msElem: msInput, msDiv: msDiv};
            Workport.MultiSelect.createMultiSelect(expertsMSObj, expertsEEObj, getExpertsIdsStr, function() {loader.show();}, function() {loader.hide();});

            submitBtn = $("#ss_share_email_submit_btn");
            submitBtn.click(btnClick);

            expertsIdsArray = "";
            expertsIdsStr = "";
        }


        function btnClick () {
            var array, len, ids, idsSelected = expertsIdsArray;
            if (!expertsIdsStr && !expertsIdsArray) {
                Workport.utils.alertMsg(winTitle, "Please select a valid user.", function(_data){});
                return;
            }
           
            if (expertsIdsStr) {
                ids = expertsIdsStr;
            }
            if (idsSelected) {
                idsSelected = idsSelected.substr(0, idsSelected.length - 1);
                if (ids) {
                    array = idsSelected.split(";");
                    len = array.length;
                    for (var i = 0; i < len; i++) {
                        if (-1 == ids.indexOf(array[i])) {
                            ids = ids + ";" + array[i];
                        }
                    }
                } else {
                    ids = idsSelected;
                }
            } 
            loader.show(); 
            Workport.StreamAPI.sendMail(function (data) {
                loader.hide();
                if (data.ResponseCode != "WP1022") {
                    Workport.utils.alertMsg(winTitle, 'An Email is triggered to the selected users with the update details.', function(_data){});
					winDiv.data("kendoWindow").close();
                    return;
                }
            },{Subject : notificationTitle, Body : notificationText, To : ids});
        };

        function getExpertsIdsStr (idsStr) {
            expertsIdsStr = idsStr;
            win.center();
        }

    	return {
            open : function (title, text, _cb) {
                notificationTitle = title;
                notificationText = text;
                callbackFun = _cb;
                init();
                win = winDiv.data("kendoWindow");
                win.center();
                win.open();
                $($("#ss_share_email_win_wnd_title").next().find("span.k-i-close")).attr("id", "ss_share_email_win_close_icon");
            }
        };
	})();
</script>